package practice.创建固定长度的线程池;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyThreadPool {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        Thread thread1 = new Thread(() -> {
            System.out.println("线程一开始啦");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程一");
        });
        Thread thread2 = new Thread(() -> {
            System.out.println("线程二开始啦");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程二");
        });
        Thread thread3 = new Thread(() -> {
            System.out.println("线程三");
        });
        executorService.submit(thread1);
        executorService.submit(thread2);
        executorService.submit(thread3);
        executorService.shutdown();
    }
}
